package com.ruoyi.production.service.impl.carton;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.domain.OrderAllocation;
import com.ruoyi.order.mapper.OrderAllocationMapper;
import com.ruoyi.production.domain.carton.CartonApply;
import com.ruoyi.production.mapper.carton.CartonApplyMapper;
import com.ruoyi.production.service.carton.ICartonApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 纸箱申请Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-11
 */
@Service
public class CartonApplyServiceImpl implements ICartonApplyService
{
    @Autowired
    private CartonApplyMapper cartonApplyMapper;
    @Autowired
    private OrderAllocationMapper orderAllocationMapper;

    /**
     * 查询纸箱申请
     *
     * @param cartonApplyId 纸箱申请ID
     * @return 纸箱申请
     */
    @Override
    public CartonApply selectCartonApplyById(Long cartonApplyId)
    {
        return cartonApplyMapper.selectCartonApplyById(cartonApplyId);
    }

    /**
     * 查询纸箱申请列表
     *
     * @param cartonApply 纸箱申请
     * @return 纸箱申请
     */
    @Override
    public List<CartonApply> selectCartonApplyList(CartonApply cartonApply)
    {
        return cartonApplyMapper.selectCartonApplyList(cartonApply);
    }

    /**
     * 新增纸箱申请
     *
     * @param cartonApply 纸箱申请
     * @return 结果
     */
    @Override
    public int insertCartonApply(CartonApply cartonApply)
    {
        Long orderAllocationId = cartonApply.getOrderAllocationId();
        OrderAllocation orderAllocation = orderAllocationMapper.selectOrderAllocationById(orderAllocationId);
        cartonApply.setOrderId(orderAllocation.getOrderId());













        cartonApply.setCreateTime(DateUtils.getNowDate());



        return cartonApplyMapper.insertCartonApply(cartonApply);
    }

    /**
     * 修改纸箱申请
     *
     * @param cartonApply 纸箱申请
     * @return 结果
     */
    @Override
    public int updateCartonApply(CartonApply cartonApply)
    {
        cartonApply.setUpdateTime(DateUtils.getNowDate());
        return cartonApplyMapper.updateCartonApply(cartonApply);
    }

    /**
     * 批量删除纸箱申请
     *
     * @param cartonApplyIds 需要删除的纸箱申请ID
     * @return 结果
     */
    @Override
    public int deleteCartonApplyByIds(Long[] cartonApplyIds)
    {
        return cartonApplyMapper.deleteCartonApplyByIds(cartonApplyIds);
    }

    /**
     * 删除纸箱申请信息
     *
     * @param cartonApplyId 纸箱申请ID
     * @return 结果
     */
    @Override
    public int deleteCartonApplyById(Long cartonApplyId)
    {
        return cartonApplyMapper.deleteCartonApplyById(cartonApplyId);
    }
}
